Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
object-assign
Advanced tools
The object-assign npm package is a polyfill for the Object.assign() method, which is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object with properties and values copied from the source objects.
Copying properties
This feature allows you to copy the properties from one or more source objects to a target object. The target object in this example ends up being { a: 1, b: 2 }.
var target = { a: 1 }; var source = { b: 2 }; var returnedTarget = objectAssign(target, source);
Merging multiple sources
object-assign can merge properties from multiple source objects into a single target object. The target object in this example ends up being { a: 1, b: 2, c: 3 }.
var target = { a: 1 }; var source1 = { b: 2 }; var source2 = { c: 3 }; var returnedTarget = objectAssign(target, source1, source2);
Overwriting properties
If the source and target object have the same key, the property in the target object will be overwritten by the property from the source object. The target object in this example ends up being { a: 1, b: 2, c: 2 }.
var target = { a: 1, b: 1 }; var source = { b: 2, c: 2 }; var returnedTarget = objectAssign(target, source);
The 'extend' package is similar to object-assign in that it is used to copy properties from one or more source objects to a target object. However, 'extend' can perform a deep copy where nested objects and arrays are also recursively copied, unlike object-assign which only performs a shallow copy.
lodash.assign is a method from the Lodash library that offers similar functionality to object-assign. It copies own enumerable properties from source objects to a target object. Lodash provides a more extensive set of utilities for working with objects, arrays, and other types, and lodash.assign is part of this larger toolkit.
deep-assign is an npm package that also copies properties from source objects to a target object, similar to object-assign. The key difference is that deep-assign supports deep copying, meaning that it can copy properties at all levels of object nesting, not just the top level.
ES6
Object.assign()
ponyfill
Ponyfill: A polyfill that doesn't overwrite the native method
$ npm install --save object-assign
var objectAssign = require('object-assign');
objectAssign({foo: 0}, {bar: 1});
//=> {foo: 0, bar: 1}
// multiple sources
objectAssign({foo: 0}, {bar: 1}, {baz: 2});
//=> {foo: 0, bar: 1, baz: 2}
// overwrites equal keys
objectAssign({foo: 0}, {foo: 1}, {foo: 2});
//=> {foo: 2}
// ignores null and undefined sources
objectAssign({foo: 0}, null, {bar: 1}, undefined);
//=> {foo: 0, bar: 1}
Assigns enumerable own properties of source
objects to the target
object and returns the target
object. Additional source
objects will overwrite previous ones.
MIT © Sindre Sorhus
FAQs
ES2015 `Object.assign()` ponyfill
The npm package object-assign receives a total of 0 weekly downloads. As such, object-assign popularity was classified as not popular.
We found that object-assign demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.